#ifndef _BATTLEFIELD_H_
#define _BATTLEFIELD_H_
#include "GL\glew.h"
#include <GL\freeglut.h>
#include "SceneObject.hpp"
#include "siut/simd/Vec3f.hpp"
using siut::simd::Vec3f;

#include <vector>


class BattleField : public SceneObject
{
  public:
  //! A constructor.
  BattleField();
  ~BattleField(); 
  /*! \brief  colorpick mouse-coordinate*/
  void setPickPoint(int x, int y); 
  /*! \brief  Returns real, float coordinate on battlefield, but in discrete, tile sized steps.*/
  Vec3f *BattleField::getPickedPos(); 
  /*! \brief Returns true if tile is EMPTY. */
  bool pickedPosEmpty(); 
  /* \brief Set specified tile to be occupied by a Tower*/
  void setActiveTileAsTower(); 
  /* \brief set specified tile to be a path tile*/
  void setTileToPath(int tileX, int tileY); 
  /* \brief Convert a tile position to real, float position. */
  void getRealCoordFromInteger(int getX, int getY, float &gridPosX, float &gridPosY); 
  /* \brief Get scale of a board tile*/
  void getScale(float &xscale, float &yscale); 

  //! picked tile coordinates
  int gridX; 
  int gridY; 

  protected:
	virtual void privateInit();
	virtual void privateRender();
	virtual void privateUpdate();

  private:
	float scale;
	float min;
	float max;
	float range;

  float xscale;
	float yscale;

  int gridWidth;
	int gridHeight;
	int mPickX, mPickY;
	Vec3f mPickedPosition;
	bool isPickUpdated_;
	std::vector< Vec3f > vertexArray_; // Maybe two-dim vector and several arrays
	
	enum state{PATHTILE, TURRETTILE, EMPTY};
	std::vector< std::vector<int> > tileState_;

	GLuint fb; // framebuffer obj handle.
	GLuint color_rb; // color renderbuffer attached to framebuffer

	//! Renders picking geometry to FBO and turns pickcolor to tilecoordinates gridX, gridY and mPickedPosition
	void renderPickColors();
	//! Called by destructor
	void ReleaseFBO();
	
	// normal array.
	// texture coord array
};

#endif //_BATTLEFIELD_H_